﻿using UnityEngine;
using System;
using System.IO;
using System.IO.Pipes;
using System.Security.Principal;
using UnityEngine.UI;
using System.Threading;

public class MyNamedPipe : MonoBehaviour
{

    public int count = 0;

    public InputField InputField;
    public Button SendBtn;

    private void Start()
    {
        Thread thread = new Thread(ServerStream);
        thread.Start();
    }

    private void ServerStream()
    {
        using (NamedPipeServerStream pipeServerStream = new NamedPipeServerStream("MyNamedPipeTest"))
        {
            Debug.Log("等待连接");
            pipeServerStream.WaitForConnection();
            
            using (StreamWriter writer = new StreamWriter(pipeServerStream))
            {
                writer.AutoFlush = true;

                int i = 0;
                while (i++ < 100)
                {
                    Thread.Sleep(1000);
                    writer.WriteLine($"Msg_{i}");
                }
            }

        }
    }
}